<!doctype html>

<head>
 
<script src="Scripts/jquery-1.7.2.min.js" type="text/javascript"></script>
 
<script type="text/javascript">
 
$(document).ready(function () {
 
var name = prompt('what is your name?:');
 
//var url = 'ws://' + window.location.hostname + window.location.pathname.replace('index.html', 'ws.ashx') + '?name=' + name;
//var url = window.location.hostname + window.location.pathname.replace('index.html', 'ws.ashx') + '?name=' + name;
var url = 'ws://localhost:62064/ws.ashx?name=' + name;

alert('Connecting to: ' + url);

ws = new WebSocket(url);
 
ws.onopen = function () {
 
$('#messages').prepend('Connected <br/>');
 
$('#cmdSend').click(function () {
 
ws.send($('#txtMessage').val());
 
$('#txtMessage').val('');
 
});
 
};
 
ws.onmessage = function (e) {
 
$('#chatMessages').prepend(e.data + '<br/>');
 
};
 
$('#cmdLeave').click(function () {
 
ws.close();
 
});
 
ws.onclose = function () {
 
$('#chatMessages').prepend('Closed <br/>');
 
};
 
ws.onerror = function (e) {
 
$('#chatMessages').prepend('Oops something went wront <br/>');
 
};
 
});
 
</script>
 
</head>
 
<body>
 
<input id="txtMessage" />
 
<input id="cmdSend" type="button" value="Send" />
 
<input id="cmdLeave" type="button" value="Leave" />
 
<br />
 
<div id="chatMessages" />
 
</body>
 
</html>